package com.spring.gop.proj.controller;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import com.spring.gop.proj.interfaces.QnaService;
import com.spring.gop.proj.model.Qna;
import com.spring.gop.proj.model.Cdt;
import com.spring.gop.proj.model.User;

@Controller
@RequestMapping("/help/qna/qna_user/*")
@SessionAttributes("qna")
public class QnaUserController {

	@Autowired private QnaService qnaService;
	
	@RequestMapping(value="/complete", method=RequestMethod.GET)
	public void complete(){}
	
	@RequestMapping(value="/insert", method=RequestMethod.GET)
	public void insertForm(Model model){}
		
	
	@RequestMapping(value="/insert", method=RequestMethod.POST)
	public String insert(HttpSession session, @ModelAttribute("newArticle") Qna qna){
		
		qna.setStep(0);
		qna.setDepth(0);
		
		User user = (User)session.getAttribute("user");
		qna.setMember_id(user.getMember_id());
		qna.setMember_name(user.getMember_name());
		
		qna.setRef(qnaService.getMaxNum()+1);
		qnaService.insertArticle(qna);
		return "redirect:complete";
	}
	
	
	
	
	
	
	
	//광고 및 제휴문의 
	@RequestMapping(value="/complete1", method=RequestMethod.GET)
	public void complete1(){}
	
	@RequestMapping(value="/insert1", method=RequestMethod.GET)
	public void insertForm1(Model model){}
		
	
	@RequestMapping(value="/insert1", method=RequestMethod.POST)
	public String insert1(HttpSession session, @ModelAttribute("newArticle") Qna qna){
		int x=0;
		qna.setStep(0);
		qna.setDepth(0);
		
		User user = (User)session.getAttribute("user");
		qna.setMember_id(user.getMember_id());
		qna.setMember_name(user.getMember_name());
		
		System.out.println(qnaService.getArticleCount2());
		if(qnaService.getArticleCount2()==0){
			qna.setRef(1);
		System.out.println("확인");	
			
		}else{
			System.out.println("확인1");
			qna.setRef(qnaService.getMaxNum1()+1);
	}
		
		qnaService.insertArticle1(qna);
		return "redirect:complete1";
	}
}	
	